package controller;


import service.AddpowerService;
import service.impl.AddpowerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/addpowerServlet")
public class AddpowerServlet extends BaseServlet {
    /**
     * 取消禁止权限
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected String addUserAddpower(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, SQLException {
        int mid = Integer.parseInt(req.getParameter("mid"));
        int uid = Integer.parseInt(req.getParameter("uid"));
        AddpowerService addpowerService = new AddpowerServiceImpl();
        boolean flag = addpowerService.addUserAddpower(mid, uid);
        req.setAttribute("mid", mid);
        if (flag) {
//            req.getRequestDispatcher("/pageServlet?action=areaUsersPage").forward(req, resp);
            return "g_/pageServlet?action=areaUsersPage";
        } else return "s_/error.jsp";
    }

    /**
     * 添加禁止权限
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected String deleteUserAddpower(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, SQLException {
        int mid = Integer.parseInt(req.getParameter("mid"));
        int uid = Integer.parseInt(req.getParameter("uid"));
        AddpowerService addpowerService = new AddpowerServiceImpl();
        boolean flag = addpowerService.deleteUserAddpower(mid, uid);
        req.setAttribute("mid", mid);
        if (flag) {
//            req.getRequestDispatcher("/pageServlet?action=areaUsersPage").forward(req, resp);
            return "g_/pageServlet?action=areaUsersPage";
        } else return "s_/error.jsp";
        //        String type=req.getParameter("type");
//        String usename=req.getParameter("usename");
//        UserDaoImpl implementUser=new UserDaoImpl();
//        User user=new User();
//        req.getParameter("type");
//        //try {
//            user=implementUser.getuser(usename);
//            implementUser.updatepower(user);
//            req.getRequestDispatcher("/findAreaUserPage").forward(req,resp);
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
    }
}
